(function() {
	const response = {
		type: 'page',
		title: '借调申请概览',
		body:[
			{
				type: "crud",
				name: "amGetAssetSecondments",
				syncLocation: false,
				"api": {
					method: "post",
					url: "/assetManager/amGetAssetSecondments",
					// adaptor: function (payload, response) {
					//
					// 	return payload;
					// }
				},
				loadDataOnce: true,
				"filterTogglable": true,
				"headerToolbar": [
					{
						type: "filter-toggler"
					},
					{
						"type": "export-excel",
						"api": "post:/assetManager/amGetAssetSecondments",
						filename: "借调申请",
						//自定义导出列
						columns:[
							"id",
							"assetName",
							"assetClasses",
							"applicantId",
							"secondmentReason",
							"classes",
							"result",
							"createTime",
							"isComplete"
						]
					},{
						type: "reload"
					}
				],
				"autoFillHeight": "true",
				//|filter:result:match:'运维人员同意'
				"source": "${items | filter:id:match:idFilter|filter:assetName:match:assetNameFilter}",
				"filter": {
					"title": "条件搜索",
					"body": [
						{
							"type": "input-text",
							"name": "idFilter",
							"label": "审批编号"
						},
						{
							"type": "input-text",
							"name": "assetNameFilter",
							"label": "资产名"
						},

					]
				},
				columns:[
					{
						name: "id",
						label: "借调id",
						// hidden: true
					},
					{
						name: "assetName",
						label: "资产名"
					},
					{
						name: "assetClasses",
						label: "资产分类"
					},
					{
						name: "applicantId",
						label: "申请人ID"
					},
					{
						name: "secondmentReason",
						label: "借调理由"
					},
					{
						name: "createTime",
						type: "date",
						fromNow: "true",
						label: "申请时间"
					},
					{
						name: "result",
						label: "申请进度"
					},
					{
						name: "isComplete",
						label: "申请状态"
					},
					{
						name: "status",
						label: "借用/调拨",
						hidden: false
					},
					{
						type: "operation",
						label: "操作",
						width: 100,
						buttons: [
							{
								label: "分配资产",
								type: "button",
								name: "allocateButton",

								actionType: "dialog",

								dialog: {
									size: "lg",
									title: "请选择目标资产",
									body:[
											{
												type: "service",//功能性容器，保存变量
												data:{
													tempId: "${id}",
												},
												body:[
													{
														type: "tpl",
														tpl: "${tempId}",
														hidden: false
													},
													{
														type: "crud",
														api: {
															method: "post",
															url: "/assetManager/getUnLockAssets",
															data: "${tempId|toInt}"

														},//获取目前选中的资产id
														columns:[
															{
																name: "id",
																label: "资产编号",
																// hidden: "true"
															},
															{
																name: "assetName",
																label: "资产名"
															},
															{
																name: "classes",
																label: "资产类型"
															},
															{
																name: "life",
																label: "有效期至"
															},
															{
																name: "supplier",
																label: "供应商"
															},
															{
																name: "status",
																label: "资产状态"
															},
															{
																"type": "operation",
																"label": "操作",
																"width": 100,
																"buttons": [
																	{
																		type: "button",
																		label: "分配资产",
																		// close: true
																		actionType: "ajax",//资产管理员创建出库申请
																		api: {
																			method: "post",
																			url: "/assetManager/insertAssetOutbound",
																			data:{
																				assetSecondmentId: "${tempId}",
																				assetId: "${id}"

																			},
																			adaptor: function (payload, response) {

																				window.location.reload();

																				return payload;
																			}
																		}

																	}
																],
																"onEvent": {
																	"click": {
																		"actions": [
																			{
																				"actionType": "refresh"
																			}
																		]
																	}
																}//刷新页面
															}

														]
													}
												]
											}
									]
								}
							}

						]
					}
				]
			},
			{
				"type": "divider"
			},
			{
				"type": "tpl",
				"tpl": "资产分库申请详情",
				"inline": false,
			},
			{
				type: "crud",
				syncLocation: false,
				"api": "post:/assetManager/amGetAssetOutbounds",
				loadDataOnce: true,
				autoFillHeight: true,
				//从响应中过滤出”完成“的出库请求
				"source": "${items | filter:isComplete:match:'完成'}",
				"headerToolbar": [
					{
						"type": "export-excel",
						"api": "post:/assetManager/amGetAssetOutbounds",
						filename: "出库申请",
						//自定义导出列
						columns:[
							"id",
							"assetManagerId",
							"assetSecondmentId",
							"repositoryId",
							"result",
							"createTime",
							"isComplete"
						]
					},{
						type: "reload"
					}
				],
				columns: [
					{
						name: "assetSecondmentId",
						label: "借调申请id"
					},
					{
						name: "id",
						label: "出库申请ID"
					},
					{
						name: "assetManagerId",
						label: "资产管理员ID"
					},
					{
						name: "repositoryId",
						label: "仓库ID"
					},
					{
						name: "result",
						label: "审批进度"
					},
					{
						name: "createTime",
						type: "date",
						fromNow: "true",
						label: "申请时间"
					},
					{
						name: "isComplete",
						label: "申请状态"
					},
					{
						"type": "operation",
						"label": "操作",
						"width": 100,
						"buttons": [
							{
								"type": "button",
								"label": "完成借调申请",
								"actionType": "ajax",
								// "reload": "secondmentList", //请求完成后刷新表格组件
								"api": {
									"method": "post",
									"url": "/assetManager/amUpdateAssetSecondment",
									"data":{
										"approvalId": "${assetSecondmentId}",
										"result": "true"
									},
									//当只剩最后一个记录的时候，再次发送审批请求后返回的status状态码为400，所以选择直接刷新
									adaptor: function (payload, response) {
										(function (){
											if(payload.status===400){
												payload.msg="申请审批完成!"
												payload.status=0;
												window.location.reload();
											}
										})();
										return payload;
									}
								},
								"id": "u:313ed32d4918"
							},
							{
								"type": "button",
								"label": "拦截借调申请",
								"actionType": "ajax",
								"api": {
									"method": "post",
									"url": "/assetManager/amUpdateAssetSecondment",
									"data":{
										"approvalId": "${assetSecondmentId}",
										"result": "false"
									},
									//当只剩最后一个记录的时候，再次发送审批请求后返回的status状态码为400，所以选择直接刷新
									adaptor: function (payload, response) {
										(function (){
											if(payload.status===400){
												payload.msg="申请审批完成!";
												payload.status=0;
												window.location.reload();
											}
										})();
										return payload;
									}
								},
								"id": "u:b4389f67f70c"
							}
						]
					}
				]
			}
		]
	}

	window.jsonpCallback && window.jsonpCallback(response);
})();
